//
//  UIImage+Creation.m
//  PiaoYoung
//
//  Created by LiTengFei on 15/1/20.
//  Copyright (c) 2015年 HugeWing Co.Ltd. All rights reserved.
//
#import "UIImage+Creation.h"
#import "UIColor+Helper.h"
@implementation UIImage (ColorCreation)

+(UIImage *) imageWithSize: (CGSize) size color: (UIColor *) color{
    UIImage *image = [[UIImage alloc] init];
    UIGraphicsBeginImageContextWithOptions( size , NO , image.scale );
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM( context , 0 , size.height );
    CGContextScaleCTM( context , 1.0 , - 1.0 );
    CGContextSetBlendMode( context , kCGBlendModeNormal );
    CGRect rect = CGRectMake( 0 , 0 , size.width , size.height );
    CGContextClipToMask( context , rect , image.CGImage );
    [color setFill];
    CGContextFillRect( context , rect );

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

+(UIImage *) imageWithColor: (UIColor *) color size: (CGSize) size{

    @autoreleasepool {

        CGRect rect = CGRectMake( 0 , 0 , size.width , size.height );

        UIGraphicsBeginImageContext( rect.size );

        CGContextRef context = UIGraphicsGetCurrentContext();

        CGContextSetFillColorWithColor( context ,

                color.CGColor );

        CGContextFillRect( context , rect );

        UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        return img;
    }
}

+(UIImage *) imageWithColor: (UIColor *) color{
    return [self imageWithColor: color size: CGSizeMake( 100 , 100 )];
}

+(UIImage *) imageWithPlaceColor{
    return [self imageWithColor: [UIColor colorE6E6E6]];
}
@end
